package com.qing.web_freemarke.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 导入Excel数据监听
 *
 * @param <T>
 */
public class ExcelImportDataListener<T> extends AnalysisEventListener<T> {
	private static final Logger LOGGER = LoggerFactory.getLogger(ExcelImportDataListener.class);


	private List<T> list = new ArrayList<>();


	/**
	 * 这个每一条数据解析都会来调用
	 *
	 * @param data    one row value. Is is same as {@link AnalysisContext#readRowHolder()}
	 * @param context
	 */
	@Override
	public void invoke(T data, AnalysisContext context) {
		LOGGER.info("解析到一条数据:{}", data.toString());
		list.add(data);
	}

	/**
	 * 所有数据解析完成了 都会来调用
	 *
	 * @param context
	 */
	@Override
	public void doAfterAllAnalysed(AnalysisContext context) {
		LOGGER.info("所有数据解析完成！");
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}


}
